home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / share / initramfs-tools / hooks / compcache < prev    next >
Text File  |  2008-08-13  |  1KB  |  70 lines

  1. #!/bin/sh
  2. set -e
  3.  
  4. if [ "$1" = prereqs ]; then
  5.   exit 0
  6. fi
  7.  
  8. . /usr/share/initramfs-tools/hook-functions
  9.  
  10. number=
  11. suffix=
  12. eval $(printf "%s" "$COMPCACHE_SIZE" | \
  13.        sed -nre 's/^ *([1-9][0-9]*) *([%KMGT]) *$/number="\1"; suffix="\2";/p')
  14.  
  15. if [ -z "$number" ] || [ -z "$suffix" ]; then
  16.   exit 0
  17. fi
  18.  
  19. manual_add_modules compcache
  20.  
  21. copy_exec /sbin/swapon
  22.  
  23. mkdir -p "$DESTDIR"/etc/udev/rules.d
  24. cat >"$DESTDIR"/etc/udev/rules.d/80-compcache.rules <<EOF
  25. KERNEL=="ramzswap0", ACTION=="add", \\
  26.   RUN+="/sbin/swapon -p 100 /dev/ramzswap0 2>/dev/null"
  27. EOF
  28.  
  29. mem_total="\$(sed -nre 's/^MemTotal:\\s*([0-9]+) kB\$/\\1/p' /proc/meminfo)"
  30.  
  31. case "$suffix" in
  32. %) kbytes="\$(($mem_total * $number / 100))" ;;
  33. K) kbytes=$(($number))                       ;;
  34. M) kbytes=$(($number * 1024))                ;;
  35. G) kbytes=$(($number * 1024 * 1024))         ;;
  36. T) kbytes=$(($number * 1024 * 1024 * 1024))  ;;
  37. esac
  38.  
  39. cat >"$DESTDIR"/scripts/init-top/compcache <<EOF
  40. #!/bin/sh
  41.  
  42. PREREQ=""
  43. prereqs()
  44. {
  45.      echo "\$PREREQ"
  46. }
  47.  
  48. case \$1 in
  49. prereqs)
  50.      prereqs
  51.      exit 0
  52.      ;;
  53. esac
  54.  
  55. # find total amount of available ram
  56. TOTAL_RAM=\$( grep MemTotal /proc/meminfo |tr -d ': [A-Z][a-z]')
  57.  
  58. # Do not use compcache on the liveCD if we have more than 512M
  59. if [ "\${BOOT}" = "casper" ]; then
  60.     if [ "\${TOTAL_RAM}" -gt 524288 ]; then
  61.         exit 0
  62.     fi
  63. fi
  64.  
  65. modprobe -Q --ignore-install compcache compcache_size_kbytes="$kbytes"
  66. EOF
  67. chmod 0755 "$DESTDIR"/scripts/init-top/compcache
  68.  
  69. # vim:set et sw=2 sts=2:
  70.